package twosigma;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
/*
 * SyncDataSet.java
 * Usage: Two Sigma Code Test. Synchroize data set among all centers
 * Author: Guannan Zhang
 * Date 3/8/2012
 */
public class SyncDataSet {

	public SyncDataSet() {

	}

	public static void main(String[] args) {
		SyncDataSet s = new SyncDataSet();
		s.sync();
	}

	public void sync() {

		try {
			//store current ids of all the centers
			ArrayList<HashSet<Integer>> centers = new ArrayList<HashSet<Integer>>();
			//store all ids and their data center
			HashMap<Integer, Integer> ids = new HashMap<Integer, Integer>();
			
			//read from std in
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			String line = br.readLine();
			int numOfDataCenters = Integer.parseInt(line);
			for (int i = 1; i <= numOfDataCenters; i++) {
				line = br.readLine();
				String[] str = line.split(" ");
				HashSet<Integer> center = new HashSet<Integer>();
				for (String s : str) {
					int id = Integer.parseInt(s);
					center.add(id);
					if (!ids.containsKey(id)) {
						ids.put(id, i);
					}

				}
				centers.add(center);
			}

			//System.out.println(centers);
			//System.out.println(ids);

			for (int i = 1; i<=centers.size(); i++) {
				HashSet<Integer> center = centers.get(i-1);
				for (Iterator<Entry<Integer, Integer>> it = ids.entrySet()
						.iterator(); it.hasNext();) {
					Entry<Integer, Integer> e = it.next();
					int id = e.getKey();
					//find a lost id, output to std out
					if(!center.contains(id)){
						System.out.println(id + " " + e.getValue() + " "+ i);
					}

				}
			}
			System.out.println("done");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
